<?php


class Recharge_mdl extends CI_Model
{
	
	const TB_RECHARGE = 'cj_recharge';
	
	public function __construct()
	{
		
		parent::__construct();
	}
	
	/**
	 * 
	 * 充值列表,支持分页
	 * @param bool $page
	 * @param int $limit
	 * @param int $offset
	 * @param String(desc,asc) $order
	 */
	public function getRechargeList($page = true,$limit = 0, $offset = 0, $order = 'DESC')
	{
		
		if ($page) {
			
			$this->db->limit(intval($limit));
			$this->db->offset(intval($offset));
			$this->db->select('recharge.id,recharge.uid,recharge.unique_identifier,recharge.createtime,recharge.gold,user.txemail')
				->from(self::TB_RECHARGE.' as recharge')
				->join('cj_users as user','user.uid=recharge.uid')
				->order_by("createtime", "desc"); 
			return $this->db->get()->result_array();
			
		} else {
			
			$reward = array();
			$this->db->select('recharge.id,recharge.uid,recharge.unique_identifier,recharge.createtime,recharge.gold,user.txemail')
					->from(self::TB_RECHARGE.' as recharge')
					->join('cj_users as user','user.uid=recharge.uid','left')
					->order_by("createtime", "desc"); 
			return $this->db->get()->result_array();
			
		}
	}
	
	
	/**
	 * 
	 * 取得recharge数 ...
	 * @return int num
	 */
	
	public function getRechargeCount()
	{
		$count = 0;
		$count =  $this->db->count_all_results(self::TB_RECHARGE);

		return $count;
	}
	
}